<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>

<form id="informationForm" role="form" method="post" action="pillControl/update">
    <input type="hidden" name="id" id="informationId" th:value="${entity.id}"/>
    <div class="form-group">
        <label for="pillNumber">发票号:</label>
        <input class="form-control" name="pillNumber" id="pillNumber" placeholder="请输入发票号" th:value="${entity.pillNumber}" />
    </div>
    <div class="form-group">
        <label for="pillMoney">发票金额:</label>
        <input type="text" class="form-control" name="pillMoney" id="pillMoney" placeholder="请输入发票金额" th:value="${entity.pillMoney}"/>
    </div>
    <div class="form-group">
        <label for="pillTime">开票时间:</label>
        <input type="date" class="form-control" name="pillTime" id="pillTime" placeholder="请输入开票时间" th:value="${entity.pillTime}"/>
    </div>
    <div class="form-group">
        <label for="pillCompany">开票公司:</label>
        <input type="text" class="form-control" name="pillCompany" id="pillCompany" placeholder="请输入开票公司" th:value="${entity.pillCompany}"/>
    </div>
    <div class="form-group">
        <label for="pillApplyPeo">发票申请人:</label>
        <input type="text" class="form-control" name="pillApplyPeo" id="pillApplyPeo" placeholder="请输入发票申请人" th:value="${entity.pillApplyPeo}"/>
    </div>
    <div class="form-group">
        <label for="pillCodeNumber">统一社会信用代码:</label>
        <input type="text" class="form-control" name="pillCodeNumber" id="pillCodeNumber"placeholder="请输入统一社会信用代码" th:value="${entity.pillCodeNumber}"/>
    </div>
    <div class="form-group">
        <label for="state">发票状态:</label>
        <select type="text" class="form-control" name="state" id="state">

        </select>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $.post("dict/getType", {type: "PILL_STATE"},
            function (r) {
            console.log(r)
                var pillState = [[${entity.state}]];
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for (var i = 0; i < r.data.length; i++) {
                    if (pillState == r.data[i].value) {
                        $("#state", window.top.document).append("<option selected=true  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    } else {
                        $("#state", window.top.document).append("<option  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }

                }
            })
        $('#informationForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                pillNumber: {
                    validators: {
                        notEmpty: {
                            message: '发票号不能为空'
                        }
                    }
                },
                pillMoney: {
                    validators: {
                        notEmpty: {
                            message: '发票金额不能为空'
                        }
                    }
                },
                pillTime: {
                    validators: {
                        notEmpty: {
                            message: '开票时间不能为空'
                        }
                    }
                },
                pillCompany: {
                    validators: {
                        notEmpty: {
                            message: '发票公司不能为空'
                        }
                    }
                },
                pillApplyPeo: {
                    validators: {
                        notEmpty: {
                            message: '开票申请不能为空'
                        }
                    }
                },
                pillMoney: {
                    validators: {
                        notEmpty: {
                            message: '发票金额不能为空'
                        }
                    }
                },
                pillState: {
                    validators: {
                        notEmpty: {
                            message: '开票状态不能为空'
                        }
                    }
                },
                pillCodeNumber: {
                    validators: {
                        notEmpty: {
                            message: '统一社会信用代码不能为空'
                        }
                    }
                }
            }
        });

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
            var bootstrapValidator = $("#informationForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.post($("#informationForm", window.top.document).attr('action'), $("#informationForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                        window.Ewin.alert({message: '修改数据成功!'});
                    } else {
                        window.Ewin.alert({message: '修改数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>